﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Lincolnwood.Foundation.Common.Data;
using Lincolnwood.Foundation.Common.Data.NHibernate;
using NHibernate;
using NHibernate.Linq;

namespace Lincolnwood.Foundation.SermonLibrary.Data.NHibernate
{
    public class NHibernateBibleBookRepository : NHibernateReferenceDataRepositoryBase<BibleBook, short>
    {
        public NHibernateBibleBookRepository(IUnitOfWork unitOfWork)
            : base((NHibernateUnitOfWork)unitOfWork)
        { }

        public IList<BibleBook> FindByName(string name)
        {
            IList<BibleBook> matches = (from b in UnitOfWork.Session.Query<BibleBook>() 
                                        where b.Name.Contains(name) || b.ShortNames.Contains(name) select b).ToList<BibleBook>();

            return matches;
        }

        public IList<BibleBook> FindByTestament(Testament testament)
        {
            IList<BibleBook> matches = (from b in UnitOfWork.Session.Query<BibleBook>() where b.Testament == testament select b).ToList<BibleBook>();

            return matches;
        }
    }
}
